package com.txunda.zhuohired.aty.login;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;
import com.smarttop.library.bean.City;
import com.smarttop.library.bean.County;
import com.smarttop.library.bean.Province;
import com.smarttop.library.bean.Street;
import com.smarttop.library.widget.AddressSelector;
import com.smarttop.library.widget.BottomDialog;
import com.smarttop.library.widget.OnAddressSelectedListener;
import com.txunda.zhuohired.R;
import com.txunda.zhuohired.base.Base2Aty;
import com.txunda.zhuohired.dialog.JoinJobDialog;
import com.txunda.zhuohired.dialog.SelectBirthdayDialog;
import com.txunda.zhuohired.dialog.SexDialog;

/**
 * 创建人： Txd_Cjh
 * 创建时间： 2018/3/10 10:25
 * 功能描述：完善简历信息(个人信息)
 * 联系方式：jiahuanchen@126.com
 */

public class PerfectResumeAty extends Base2Aty implements AddressSelector.onSelectorAreaPositionListener,
        OnAddressSelectedListener, AddressSelector.OnDialogCloseListener {
    /**
     * 标题
     */
    @ViewInject(R.id.tv_layout_blue_center)
    private TextView tv_layout_blue_center;
    /**
     * 性别
     */
    @ViewInject(R.id.tv_perfect_resume_sex)
    private TextView tv_perfect_resume_sex;
    /**
     * 出生年月
     */
    @ViewInject(R.id.tv_perfect_resume_birthday)
    private TextView tv_perfect_resume_birthday;
    /**
     * 参加工作时间
     */
    @ViewInject(R.id.tv_perfect_resume_join_job_time)
    private TextView tv_perfect_resume_join_job_time;
    /**
     * 现居地
     */
    @ViewInject(R.id.tv_perfect_resume_city)
    private TextView tv_perfect_resume_city;

    private BottomDialog dialog;
    private int provincePosition;
    private int cityPosition;
    private int countyPosition;
    private int streetPosition;
    private String provinceCode;
    private String cityCode;
    private String countyCode;
    private String streetCode;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        showStatusBar(R.id.layout_blue_head);
        tv_layout_blue_center.setText("完善简历信息");
    }

    @Override
    @OnClick({R.id.ll_personal_sex, R.id.ll_perfect_resume_birthday, R.id.ll_perfect_resume_join_job_time, R.id
            .ll_perfect_resume_city, R.id.tv_perfect_resume_next})
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.ll_personal_sex://性别
                SexDialog sexDialog = new SexDialog(this, new SexDialog.SexListener() {
                    @Override
                    public void onSex(String type) {
                        tv_perfect_resume_sex.setText(type);
                    }
                });
                sexDialog.show();
                break;
            case R.id.ll_perfect_resume_birthday://选择出生年月
                SelectBirthdayDialog selectBirthdayDialog = new SelectBirthdayDialog(this, new SelectBirthdayDialog
                        .SelectBirthdayListener() {


                    @Override
                    public void onSelectBirthday(String birthday) {
                        tv_perfect_resume_birthday.setText(birthday);
                    }
                });
                selectBirthdayDialog.show();
                break;
            case R.id.ll_perfect_resume_join_job_time://参加工作时间
                JoinJobDialog joinJobDialog = new JoinJobDialog(this,"2", new JoinJobDialog.JoinJobListener() {
                    @Override
                    public void onJoinJob(String birthday) {
                        tv_perfect_resume_join_job_time.setText(birthday);
                    }
                });
                joinJobDialog.show();
                break;
            case R.id.ll_perfect_resume_city://现居地
                if (dialog != null) {
                    dialog.show();
                } else {
                    dialog = new BottomDialog(this);
                    dialog.setOnAddressSelectedListener(this);
                    dialog.setDialogDismisListener(this);
                    dialog.setTextSize(14);//设置字体的大小
                    dialog.setIndicatorBackgroundColor(android.R.color.holo_orange_light);//设置指示器的颜色
                    dialog.setTextSelectedColor(android.R.color.holo_orange_light);//设置字体获得焦点的颜色
                    dialog.setTextUnSelectedColor(android.R.color.holo_blue_light);//设置字体没有获得焦点的颜色
                    //            dialog.setDisplaySelectorArea("31",1,"2704",1,"2711",0,"15582",1);//设置已选中的地区
                    dialog.setSelectorAreaPositionListener(this);
                    dialog.show();
                }
                break;
            case R.id.tv_perfect_resume_next://下一步
                startActivity(PerfectResumeApplyAty.class, null);
                break;
        }
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.aty_perfect_resume;
    }

    @Override
    protected void initialized() {

    }

    @Override
    protected void requestData() {

    }

    @Override
    public void selectorAreaPosition(int provincePosition, int cityPosition, int countyPosition, int streetPosition) {
        this.provincePosition = provincePosition;
        this.cityPosition = cityPosition;
        this.countyPosition = countyPosition;
        this.streetPosition = streetPosition;
    }

    @Override
    public void onAddressSelected(Province province, City city, County county, Street street) {
        provinceCode = (province == null ? "" : province.code);
        cityCode = (city == null ? "" : city.code);
        countyCode = (county == null ? "" : county.code);
        streetCode = (street == null ? "" : street.code);
        String s = (province == null ? "" : province.name) + "-" + (city == null ? "" : city.name) + "-" + (county ==
                null ? "" : county.name);
        tv_perfect_resume_city.setText(s);
        if (dialog != null) {
            dialog.dismiss();
        }
    }

    @Override
    public void dialogclose() {
        if (dialog != null) {
            dialog.dismiss();
        }
    }
}
